<template>
	<view>
		<view class="topnav">
			<van-nav-bar
			  title="地址编辑"
			  left-arrow
			  @click-left="onClickLeft"
			/>
		</view>
		
		<view class="address">
			<van-address-edit
			  :area-list="areaList"
			  show-set-default
			  show-search-result
			  :search-result="searchResult"
			  :area-columns-placeholder="['请选择', '请选择', '请选择']"
			  @save="onSave"
			  @click-area="onArea"
			/>
			
		</view>
	</view>
</template>

<script>
	import { Toast } from 'vant';
	import {areaList} from '@vant/area-data'
	import store from '../../store/index.js'
	import {Address} from '../../request/api.js'
	export default {
		data() {
			return {
				 areaList,
				searchResult: [],
			}
		},
		methods: {
			onClickLeft(){
				uni.navigateBack({
					delta: 1
				});
			},
			//点击保存的事件
			onSave(val){
				// store.commit('setAdd',val)
				// console.log(val,store.state.user.addre);
				let data = {
					addre:val.province+val.city+val.county+val.addressDetail,
					tel:val.tel,
					aname:val.name,
					isDefault:val.isDefault,
					uid:store.state.user.addre
				}
				Address(data,(res)=>{
					if(res.code==200){
						this.$notify({type:'success',message:res.msg})
						uni.navigateTo({
							url:'/pages/myaddress/myaddress'
						})
					}else{
						this.$notify(res.msg)
					}
				})
				// this.$notify({type:'success',message:'添加地址成功'})
				// uni.navigateTo({
				// 	url:'/pages/myaddress/myaddress'
				// })
			},
			onArea(){
				
			}
		}
	}
</script>

<style lang="less">

</style>
